<template>
  <div class="app-container">
    <el-form label-width="120px">
    请填写关于我们
      
      <el-form-item label="关于我们">
         <pan-thumb :image="brief.pic" />
        <!-- 文件上传按钮 -->
        <el-button
          type="primary"
          icon="el-icon-upload"
          @click="imagecropperShow = true"
          >上传图片
        </el-button>
        <!--v-show：是否显示上传组件
:key：类似于id，如果一个页面多个图片上传控件，可以做区分
:url：后台上传的url地址
@close：关闭上传组件
@crop-upload-success：上传成功后的回调 -->
        <image-cropper
          v-show="imagecropperShow"
          :width="70"
          :height="70"
          :key="imagecropperKey"
          :url="BASE_API + '/oss/fileUpload'"
          field="file"
          @close="close"
          @crop-upload-success="cropSuccess"
        />
      </el-form-item>

      <el-form-item label="简介：">
        <el-input

          type="textarea"
          :rows="4"
          placeholder="请输入内容"
          v-model="brief.description"  style="width:600px">
        </el-input>
      </el-form-item>

      <el-form-item label="Tel">
        <el-input v-model="brief.tel"  style="width:200px" />
      </el-form-item>
      <el-form-item label="WeChat">
        <el-input v-model="brief.wechat"  style="width:200px" />
      </el-form-item>
      <el-form-item label="Address">
        <el-input v-model="brief.address"  style="width:200px" />
      </el-form-item>

      <el-form-item>
        <el-button
          :disabled="saveBtnDisabled"
          type="primary"
          @click="saveOrUpdate()"
          >保存</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import aboutUsShow from "@/api/setting";
import ImageCropper from "@/components/ImageCropper";
import PanThumb from "@/components/PanThumb";

export default {
  components: { PanThumb, ImageCropper },
  data() {
    return {   
      
      brief: {
        pic:"",
        description: "",
        tel: "",
        wechat:"",
        address:"",
      },
      saveBtnDisabled: false, // 保存按钮是否禁用,
      imagecropperShow: false, //头像上传组件是否显示
      imagecropperKey: 0,
      BASE_API: process.env.BASE_API, //获取dev.env.js里面的地址
    };
  },
  created() {
    //页面渲染之前执行
    this.init();
  },
  watch: {
    //监听
    $route(to, from) {
      //路由变化方式，路由发生变化，方法就会执行
      this.init();
    },
  },
  methods: {
    close() {
      //关闭上传头像组件
      this.imagecropperShow = false;
      //上传失败后，重新打开上传组件时初始化组件，否则显示上一次的上传结果
      this.imagecropperKey = this.imagecropperKey + 1;
    },
    cropSuccess(data) {
      //上传成功后返回的图片地址
      this.brief.pic = data.fileUrl;
      //上传头像成功
      this.imagecropperShow = false;
      //上传成功后，重新打开上传组件时初始化组件，否则显示上一次的上传结果
      this.imagecropperKey = this.imagecropperKey + 1;
    },
    init() {
         aboutUsShow.getCurrentAboutUsShow().then((response) => {
         this.brief = response.object;
      });
    },
     saveOrUpdate() {
        aboutUsShow.updateAboutUsShow(this.brief).then((response) => {
        //提示信息
        this.$message({
          type: "success",
          message: "修改成功!",
        });
      });
     }
   
  },
};
</script>
